using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 生产物品控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ProductionItemController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public ProductionItemController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取生产物品列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<ProductionItemDto>>> GetProductionItems([FromQuery] ProductionItemQueryDto query)
        {
            return await _consoleService.GetProductionItemsAsync(query);
        }

        /// <summary>
        /// 获取生产物品详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<ProductionItemDto>> GetProductionItem(int id)
        {
            return await _consoleService.GetProductionItemAsync(id);
        }

        /// <summary>
        /// 创建生产物品
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<ProductionItemDto>> CreateProductionItem([FromBody] ProductionItemDto dto)
        {
            return await _consoleService.CreateProductionItemAsync(dto);
        }

        /// <summary>
        /// 更新生产物品
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<ProductionItemDto>> UpdateProductionItem([FromBody] ProductionItemDto dto)
        {
            return await _consoleService.UpdateProductionItemAsync(dto);
        }

        /// <summary>
        /// 删除生产物品
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteProductionItem(int id)
        {
            return await _consoleService.DeleteProductionItemAsync(id);
        }
    }
} 